package AwsSES;


import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.*;
import java.net.SocketTimeoutException;
import java.util.Date;
import java.util.LinkedList;

public class SimpleEmailExemple {

    public static final String ACCESS_KEY = "AKIAJICRH6ZVS7ENHQMA";
    public static final String SECRET_KEY = "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";

    public static void main(String[] args) throws SocketTimeoutException {

        AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
        AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(credentials);

        //RECEBIMENTO DE ESTATISTICAS
//        GetSendStatisticsResult estatisticas = new GetSendStatisticsResult();
//        estatisticas = sesClient.getSendStatistics();
//        System.out.println(estatisticas);

//        GetSendQuotaResult cotaEnvio = new GetSendQuotaResult();
//        cotaEnvio = sesClient.getSendQuota();
//        System.out.println("COTA DE ENVIO: " + cotaEnvio);

//        ListIdentitiesResult listaIdentidades = new ListIdentitiesResult();
//        listaIdentidades = sesClient.listIdentities();
//
//        List<String> lista = listaIdentidades.getIdentities();
//
//        for (String identidade : lista) {
//            System.out.println("IDENTIDADE: " + identidade);
//        }
//
//        List<String> listaEnderecos = sesClient.listVerifiedEmailAddresses().getVerifiedEmailAddresses();
//
//        for (String enderecos : listaEnderecos) {
//            System.out.println("ENDEREÇOS: " + enderecos);
//        }

        LinkedList<String> recipients = new LinkedList<String>();
        //recipients.add("success@simulator.amazonses.com"); 
        //recipients.add("bounce@simulator.amazonses.com");
        //recipients.add("ooto@simulator.amazonses.com"); 
        //recipients.add("complaint@simulator.amazonses.com"); 
        //recipients.add("suppressionlist@simulator.amazonses.com");
        recipients.add("bruno.maria@delphos.com.br"); 
        Destination destinatarios = new Destination(recipients);

        SendEmailResult resultado;
        Content subjectContent = new Content("Teste de Envio de Email SES");
        Content bodyContent = new Content("Teste de Envio de Email SES " + new Date());
        Body msgBody = new Body(bodyContent);
        Message msg = new Message(subjectContent, msgBody);

        SendEmailRequest request = new SendEmailRequest("bsm@brunomaria.com.br", destinatarios, msg);

        for (int i = 0; i < 10; i++) {

            try {

                resultado = sesClient.sendEmail(request);
                System.out.println("MENSAGEM ENVIADA: Nº " + i + " - " + resultado.getMessageId());

            } catch (MessageRejectedException mr) {
                System.out.println("EXCEPTION: " + mr.getMessage());

            } catch (Exception e) {
                System.out.println("EXCEPTION: " + e.getMessage());
            }

        }
    }
}
